package com.gw.vip.common.exception;

import com.gw.vip.common.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author GW
 * @description
 * @since 2022-03-31
 */
@ResponseBody
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    @ResponseStatus(HttpStatus.OK)
    public Result businessException(BusinessException ex){
        log.warn("", ex);
        return Result.failure(ex.getCode(), ex.getMessage());
    }

    @ExceptionHandler(ServiceException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Result serviceException(ServiceException ex){
        log.error("", ex);
        return Result.failure(ex.getCode(), ex.getMessage());
    }
}
